wayland: Protect against invalid keymaps gotten from the compositor
authorCarlos Garnacho <carlosg@gnome.org>
Mon, 25 Aug 2014 13:55:22 +0000 (15:55 +0200)
committerCarlos Garnacho <carlosg@gnome.org>
Tue, 26 Aug 2014 11:04:08 +0000 (13:04 +0200)
If the compositor sends a keymap that fails on "compilation",
xkb_keymap_new_from_string() returns NULL, which makes xkb_state_new()
crash when assuming there is a keymap.

In these cases, gdk must remain with a xkb_state to handle modifiers/keys
properly, so warn about the invalid keymap string, and keep the previous
keymap (currently initialized to "us")

https://bugzilla.gnome.org/show_bug.cgi?id=735389

gdk/wayland/gdkkeys-wayland.c

index 4e8e739cb962b360c4559305ba329859258620fc..d7341446c4df7ccac925e1c4ef734b3bd5259242 100644 (file)
@@ -487,6 +487,7 @@ _gdk_wayland_keymap_update_from_fd (GdkKeymap *keymap,
 {
   GdkWaylandKeymap *keymap_wayland = GDK_WAYLAND_KEYMAP (keymap);
   struct xkb_context *context;
+  struct xkb_keymap *xkb_keymap;
   char *map_str;
 
   context = xkb_context_new (0);
@@ -498,11 +499,20 @@ _gdk_wayland_keymap_update_from_fd (GdkKeymap *keymap,
       return;
   }
 
-  xkb_keymap_unref (keymap_wayland->xkb_keymap);
-  keymap_wayland->xkb_keymap = xkb_keymap_new_from_string (context, map_str, format, 0);
+  xkb_keymap = xkb_keymap_new_from_string (context, map_str, format, 0);
   munmap (map_str, size);
   close (fd);
 
+  if (!xkb_keymap)
+    {
+      g_warning ("Got invalid keymap from compositor, keeping previous/default one");
+      xkb_context_unref (context);
+      return;
+    }
+
+  xkb_keymap_unref (keymap_wayland->xkb_keymap);
+  keymap_wayland->xkb_keymap = xkb_keymap;
+
   xkb_state_unref (keymap_wayland->xkb_state);
   keymap_wayland->xkb_state = xkb_state_new (keymap_wayland->xkb_keymap);